<?php
/**
 * 攀枝花市智慧人社就医服务中间件
 *
 *
 * @author jack
 */

namespace Pzhrs\Controller;

class PzhMedicalTestControlController
{
    // SoapClient 对象
    private $soap = FALSE;

    // 记录是否为正式环境
    private $isFormal = FALSE;

    //是否开启缓存
    private static $CACHE = false;

    // 医疗机构科室列表缓存建
    private static $CACHE_INSTITUTION_CLASS_LIST = 'CACHE_INSTITUTION_CLASS_LIST';


    static $URL_API = 'http://220.166.60.252:8083/wxjk.dll/wsdl/Iwxjk';//http://192.168.203.55:8078/HisService.asmx?WSDL
    static $back_URL_API = "http://localhost:8081/";

    //医院id
    private $hospitalId;

    //自助机id
    private $userId;

    /**
     * 构造函数
     */
    function __construct()
    {
        header('Content-Type: text/html; charset=utf-8');
        $this->hospitalId = 75;
        if (!method_exists($this, ACTION_NAME)) {
            $function = ACTION_NAME;
            A('Receive')->$function();
        }
    }

    public function xml_to_array($list){
        $ob= simplexml_load_string($list);
        $json  = json_encode($ob);
        $configData = json_decode($json, true);
        return $configData;
    }

    public $hospitalKey = array(
        "75" => "7daf7603429012aeae417fa9beed9c75",
    );
    //正式地址
    //	static $URL_API = "http://125.64.9.81:8088/rmc/mobile/web";
    //	static $version = "2.2.7";
    //	private $token = "6a2967e64a994e54b533aa7942328179";
    //正式地址


    // 	static $URL_API = "http://125.64.9.81:8088/rmc/mobile/web";
    /**
     * 请求His API
     *
     *   使用SoapClient请求HIS webservice接口
     *
     * @param String $Flag 类型
     * @param String $Content xml请求内容
     * @param String $Result_K 返回xml中的跟节点key
     *
     * @return array
     */


    private function soapGetDate($Flag, $Content)
    {
//        $this->isFormal = ($_SERVER['SERVER_NAME']!="localhost" && "histest.mobimedical.cn"!=$_SERVER['SERVER_NAME']);
        $this->isFormal = false;

        if (!$this->soap) {
            $this->soap = new \SoapClient(self::$URL_API, array("connection_timeout" => 15));
        }
        try {

            /* 正式环境 */
            if ($this->isFormal) {
                //专线接口,走平台
                try {
                    $result = $this->soap->Weixin($Content);
                } catch (\Exception $e) {
                    $fileContent = $Content . "\n" . $e->getMessage();
                    $dir = "soapGetDate/";
                    \Org\Util\File::createDir($dir);
                    file_put_contents($dir . $Flag . "_error.txt", $fileContent);
                    return array('ResultCode' => -1, "ErrorMsg" => "系统异常，请稍后重试21！");
                }
                $Result_K = "Weixin" . Result;

                /* 测试环境 */
            } else {
                $result = $this->soap->$Flag( $Content);
                /* 记录请求日志   */
                $fileContent = $Content . "\r" . var_export($result, true);
                $dir = "soapGetDate/" . date("Y-m-d") . "/" . $Flag . "/";
                $filename = date("H_i_s") . "_" . rand(10000, 99999);
                writeLog($dir, $filename, $fileContent);

                return json_decode(json_encode(json_decode(json_encode((array)simplexml_load_string(substr($result, 54)), true))), true);
            }


        } catch (\Exception $e) {
            /* 记录请求异常日志  */
            $fileContent = $Content . "\n" . $e->getMessage();
            $dir = "soapGetDate/" . date("Y-m-d") . "/" . $Flag . "/";
            $filename = date("H_i_s") . "_error";
            writeLog($dir, $filename, $fileContent);
            return array('ResultCode' => -1, "ErrorMsg" => "系统异常，请稍后重试22！");
            exit;
        }
    }


    function Post($url, $method, $post = null)
    {
        if (is_array($post)) {
            ksort($post);
            $content = http_build_query($post);
            $content_length = strlen($content);
            $options = array(
                'http' => array(
                    'method' => 'POST',
                    'header' =>
                        "Content-type: application/x-www-form-urlencoded; charset=utf-8\r\n" .
                        "Content-length: $content_length\r\n",
                    'content' => $content
                )
            );
            $res = file_get_contents($url, false, stream_context_create($options));
            $fileContent = var_export($post, true) . "\r" . var_export($res, true) . "\r" . var_export(json_decode($res, true), true);
            $dir = "soapGetDateXt/" . date("Y-m-d") . "/" . $method . "/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
            return $res;
        }
    }

    /**
     * 中间件签名验证
     * @param array $params
     * @return string
     */
    function middelEnCodeSign($params)
    {
        ksort($params);
        $preString = "";
        $time = $params['time'];
        $hospitalId = $params['hospitalId'];
        foreach ($params as $k => $v) {
            if ($k == 'time' || $k == 'sign' || !$v)
                continue;
            $preString .= $k . "=" . $v;
        }

        $keyString = $this->hospitalKey[$hospitalId];
        //加密
        return sha1($preString . $keyString . $time);
    }


    /**
     * 确认病人信息  绑卡
     * @param $car_no '就诊卡号'
     * @param $user_name '病人姓名'
     */
    public function cardInfoQuery()
    {
//        $sign       = $this->middelEnCodeSign($_POST);
//        if($sign!=$_POST['sign']){
//            echo "签名不正确";exit;
//        }
        $card_no    = $_POST['identy_id'];
        $user_name  = $_POST['user_name'];

        //$card_no = '600143066';

        $Content ="<HIS><card_no>".$card_no."</card_no></HIS>";

        $searchKey = "patient";
        $result = $this->soapGetDate($searchKey, $Content);
        if ($result['status'] == 0 && !empty($result['data']['name'])) {
            if ($result['data']['name'] == $user_name && $result['status'] == 0) {
                $returnArr['status'] = 1;
                $returnArr['errorMsg'] = "绑卡成功";
                $returnArr['data'] = $result['Data'];
            } else {
                $returnArr['status'] = 2;
                $returnArr['errorMsg'] = "姓名输入有误";
                $returnArr['data'] = array();
            }

        } else {
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result['ResultMsg'];
            $returnArr['data'] = array();

        }

        echo json_encode($returnArr);
    }

    public function Test_jj()
    {
        //echo '122';die();
        //$client = new \SOAPClient('http://192.168.100.149:9192/OrderTreat/services/HosiptalManager?wsdl');
        $url='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $s=new \SoapClient($url);
        /*
         *SoapHeader参数说明如下所示:
         *'http://tempuri.org/'   namespace(命名空间可省略)
         *'MySoapHeader'          SoapHeader头的类名
         *'array(...)'            存放标识身份的字符串参数
         *'true'                  是否必须处理该header
        */
        $mmkj='http://yinhai.com';
        $code='yinhai@789'; //授权码
        $funNo='WX_001';    //交易编号 
        $xml_xx="<input><aac001>4000612523</aac001><startrow>1</startrow><endrow>3</endrow><inputxml><inputxml><aac002>510402198306076317</aac002><aac003>张帆</aac003></inputxml></inputxml></input>";
        $apiUrl='http://pzh.91cure.com/index.php?g=Home&m=Test&a=pzh_sign';
        $params1 = array();
        $params1['content']=$xml_xx;
        $xmlsing=$this->PostData_jm($apiUrl,$params1);

        $auth_header = array( "jybh" =>$funNo ,"systemKey" =>$code ,"source" =>$xml_xx,"signature" =>$xmlsing  );
        $authvalues = new \SoapVar($auth_header, SOAP_ENC_OBJECT,"system",$mmkj);  
        $u = new \SoapHeader($mmkj, 'system', $authvalues);
        $s->__setSoapHeaders($u);
        $params['inputxml']=$xml_xx;
        $suc=$s->callBusiness($params);
        $data=$suc->return;
        $tesres = $this->xml_to_array($data);
        dump($tesres);
    }
    //养老保险查询
    function EndowmentInsurance_Query(){
        $identyId='510402198306076317';   //身份证号码
        $name='张帆';       //姓名
        $funNo='WX_001';    //交易编号
        $xml="<input><aac001>4000612523</aac001><startrow>1</startrow><endrow>3</endrow><inputxml><inputxml><aac002>".$identyId."</aac002><aac003>".$name."</aac003></inputxml></inputxml></input>";
        $url='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $client=new \SoapClient($url);
        dump($xml);
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        $datares=$result_list['output']['row'];
        if($result_list['code']=='1'){
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$result_list['message'];
            $returnArr['data']['name']=$name;                   //姓名
            $returnArr['data']['identyId']=$identyId;           //身份证号码
            $returnArr['data']['insured_units']=$datares['aab004'];     //参保所在单位名称
            $returnArr['data']['insured_status']=$datares['aac008'];    //参保状态
            $returnArr['data']['payment_status']=$datares['aac031'];    //缴费状态
            $returnArr['data']['payment_max_period']=$datares['aae002'];    //最大缴费期号
            $returnArr['data']['payment_total_local']=$datares['aic027'];   //在本地缴费总金额
            $returnArr['data']['payment_total_monthly']=$datares['aic079']; //累计缴费总月数
            $returnArr['data']['payment_total_money']=$datares['aic040'];   //截至当前个人账户累计存储额         
            //echo json_encode($returnArr);exit;
        }else{//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $result_list['message'];
        };
        dump($returnArr);
    }
    //pzh数据加密
    public function kkkzh_sign1(){
         //echo '123';//die();
        $hospitalId = 1;
        //echo '125';die();
        $content='<input><inputxml><inputxml><yad901>tcyl_oeTsDvx_c9sJhQ3XrqxBeVsfDJxY</yad901></inputxml></inputxml></input>';
        //$rsaPrivateKeyPem='http://pzh.91cure.com/bcp.keystore';
        $rsaPrivateKeyPem='http://127.0.0.1:11088/bcp.keystore';
        //echo '123';die();
        $content = htmlspecialchars_decode($content);
        $priKey = file_get_contents($rsaPrivateKeyPem);
        echo  $priKey;  //die();
        $res = openssl_pkey_get_private($priKey);
        openssl_sign($content, $sign, $res);
        openssl_free_key($res);  
        echo  'sign123';
        //$sign = base64_encode($sign);  
        $sign = bin2hex($sign);
        //echo $content_jj;
        //var_dump($content_jj);
        //echo "<br>";
        echo $sign;
        return $sign;  

    }

    /**
     * 统一调接口方法 
     * $xml       接口传递的参数
     * $funNo     接口的方法名
     * $client    接口需要调用的webservice对象 
     * */
    function Get_service_api($xml,$funNo,$client){
        $mmkj='http://yinhai.com';
        $code='wx20170921'; //授权码yinhai@789  
        //$apiUrl='http://pzh.91cure.com/index.php?g=Home&m=Test&a=pzh_sign';
        $apiUrl='http://pzhrs.91cure.com/index.php?g=Home&m=Test&a=pzh_sign';//正式前置机
        $params1 = array();
        $params1['content']=$xml;
        $xmlsing=$this->PostData_jm($apiUrl,$params1);
        echo strlen($xmlsing);
        //echo "<br>";
        //echo strlen($xmlsing1);
        //echo "<br>";
        dump($xmlsing);
        dump($params1);//die();
        $auth_header = array( "jybh" =>$funNo ,"systemKey" =>$code ,"source" =>$xml,"signature" =>$xmlsing  );
        echo $auth_header;
        $authvalues = new \SoapVar($auth_header, SOAP_ENC_OBJECT,"system",$mmkj);  
        $u = new \SoapHeader($mmkj, 'system', $authvalues);
        $client->__setSoapHeaders($u);
        $params['inputxml']=$xml;
        $suc=$client->callBusiness($params);
        $data=$suc->return;
        //dump($suc);
        $tesres = $this->xml_to_array($data);
        return  $data;
    }
    /**
     * 数字签名
     * $url         签名地址
     * $post        签名参数
     * */
    function PostData_jm($url, $post = null) {
        dump($url);
        if (is_array($post)) {
            ksort($post);
            $content = http_build_query($post);
            $content_length = strlen($content);
            $options = array(
                'http' => array(
                    'method' => 'POST',
                    'header' =>
                    "Content-type: application/x-www-form-urlencoded\r\n"."Content-length: $content_length\r\n",
                    'content' => $content
                )
            );
            $now = time();
            print_r($options);
            $context = stream_context_create($options);
            //echo $context;
            $res = file_get_contents($url, false, $context);
            echo '-11111-';
            echo $res;die();
            return substr(urlencode($res),9);//
            //return $res;
        }
    }

    /**
     * 医院信息
     * @param 
     */
    function GetHospitalInformation(){
        $funNo='HIS015';    //交易编号
        $xml="<input><startrow>1</startrow><endrow>100</endrow></input>";
        //dump(C('URL_API'));die();
        dump($xml);
        $client=new \SoapClient(C('URL_API'));
        //$client='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);

        $te_arry=$result_list['output']['resultset']['row']['akb020'];
        $ywsz_jj=$result_list['output']['resultset']['row'];
        if(is_array($result_list['message']))
        {
            $llmessage='';  
        }else{
            $llmessage=$result_list['message']; 
        }; 
        if($result_list['code']=='1')
        {
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;   
            if($te_arry)
            {
                $returnArr['data'][0]['hospitalCode']=$ywsz_jj['akb020'];   //医院代码
                $returnArr['data'][0]['hospitalName']=$ywsz_jj['akb021'];   //医院名称
                $returnArr['data'][0]['hospitalAddress']=$ywsz_jj['aae006'];    //医院地址
                $returnArr['data'][0]['hospitalPhone']=$ywsz_jj['aae005'];      //联系电话
                $returnArr['data'][0]['hospitalGrade']=$ywsz_jj['aka101'];     //医院等级
                //$returnArr['data'][0]['hospitalDescription']=$ywsz_jj['aae013'];     //医院描述
                if(is_array($ywsz_jj['aae013']))
                {
                    $returnArr['data'][0]['hospitalDescription']='';  //医院描述
                }else
                {
                    $returnArr['data'][0]['hospitalDescription']=$ywsz_jj['aae013']; 
                };
            } else { 
                foreach ($ywsz_jj as $k => $v) {
                    $returnArr['data'][$k]['hospitalCode']=$ywsz_jj[$k]['akb020'];   //医院代码
                    $returnArr['data'][$k]['hospitalName']=$ywsz_jj[$k]['akb021'];   //医院名称
                    $returnArr['data'][$k]['hospitalAddress']=$ywsz_jj[$k]['aae006'];    //医院地址
                    $returnArr['data'][$k]['hospitalPhone']=$ywsz_jj[$k]['aae005'];      //联系电话
                    $returnArr['data'][$k]['hospitalGrade']=$ywsz_jj[$k]['aka101'];     //医院等级
                    //$returnArr['data'][0]['hospitalDescription']=$ywsz_jj[$k]['aae013'];     //医院描述
                    if(is_array($ywsz_jj[$k]['aae013']))
                    {
                        $returnArr['data'][$k]['hospitalDescription']='';  //医院描述
                    }else
                    {
                        $returnArr['data'][$k]['hospitalDescription']=$ywsz_jj[$k]['aae013']; 
                    };
                }
            }
        }else
        {//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };
        dump($returnArr);
        /* 记录请求日志   */
            $fileContent = var_export($returnArr, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetHospitalInformation_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        echo json_encode($returnArr);
    }

    /**
     * 科室信息
     * @param 
     */
    function GetDepartment(){
        $hospitalCode='525009'; //医院编码 525009
        $deptCode='';       //科室编号
        $funNo='HIS001';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><deptcode>".$deptCode."</deptcode><functionid>".$funNo."</functionid><akb020>".$hospitalCode."</akb020></Request></input>";
        dump($xml);//die();

        $client=new \SoapClient(C('URL_API'));
        //$client='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);
        echo $result_list;die();
        //dump($result_list);
        $te_arry=$result_list['item']['deptCode'];
        $ywsz_jj=$result_list['item'];
        if(is_array($result_list['resultMessage']))
        {
            $llmessage='';  
        }else{
            $llmessage=$result_list['resultMessage']; 
        }; 
        if($result_list['resultCode']=='1')
        {
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;   
            if($te_arry)
            {
                $returnArr['data'][0]['hospitalCode']=$hospitalCode;    //医院代码
                $returnArr['data'][0]['deptCode']=$ywsz_jj['deptCode'];     //科室代码
                $returnArr['data'][0]['deptName']=$ywsz_jj['deptName'];     //科室名称
                $returnArr['data'][0]['hasChild']=$ywsz_jj['hasChild'];     //是否有子科室 0：无子科室1：有子科室
                $returnArr['data'][0]['parentDeptCode']=$ywsz_jj['parentDeptCode'];//父科室代码 0：无父科室
                //$returnArr['data'][0]['deptDescription']=$ywsz_jj['deptDescription'];   //科室介绍
                //$returnArr['data'][0]['deptLocation']=$ywsz_jj['deptLocation'];   //科室位置描述

                if(is_array($ywsz_jj['deptDescription']))
                {
                    $returnArr['data'][0]['deptDescription']='';  //科室介绍
                }else
                {
                    $returnArr['data'][0]['deptDescription']=$ywsz_jj['deptDescription']; 
                };

                if($ywsz_jj['deptLocation']=='null')
                {
                    $returnArr['data'][0]['deptLocation']='';  //科室位置描述
                }else
                {
                    $returnArr['data'][0]['deptLocation']=$ywsz_jj['deptLocation']; 
                };
            } else { 
                foreach ($ywsz_jj as $k => $v) {
                    $returnArr['data'][$k]['hospitalCode']=$hospitalCode;    //医院代码
                    $returnArr['data'][$k]['deptCode']=$ywsz_jj[$k]['deptCode'];     //科室代码
                    $returnArr['data'][$k]['deptName']=$ywsz_jj[$k]['deptName'];     //科室名称
                    $returnArr['data'][$k]['hasChild']=$ywsz_jj[$k]['hasChild'];     //是否有子科室 0：无子科室1：有子科室
                    $returnArr['data'][$k]['parentDeptCode']=$ywsz_jj[$k]['parentDeptCode'];//父科室代码 0：无父科室
                    if(is_array($ywsz_jj[$k]['deptDescription']))
                    {
                        $returnArr['data'][$k]['deptDescription']='';  //科室介绍
                    }else
                    {
                        $returnArr['data'][$k]['deptDescription']=$ywsz_jj[$k]['deptDescription']; //科室位置描述
                    };

                    if($ywsz_jj[$k]['deptLocation']=='null')
                    {
                        $returnArr['data'][$k]['deptLocation']='';  //科室位置描述
                    }else
                    {
                        $returnArr['data'][$k]['deptLocation']=$ywsz_jj[$k]['deptLocation']; //科室位置描述
                    };
                }
            }
        }else
        {//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };
        //dump($returnArr);
        /* 记录请求日志   */
            $fileContent = var_export($returnArr, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetDept_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        echo json_encode($returnArr, JSON_UNESCAPED_UNICODE);
        //echo json_encode($returnArr);
    }

    /**
     * 医生信息
     * @param 
     */
    function GetDoctor(){
        $hospitalCode='525001'; //医院编码
        $deptCode='';       //科室编号
        $doctorCode='';       //医生编号
        $funNo='HIS002';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><deptcode>".$deptCode."</deptcode><doctorcode>".$doctorCode."</doctorcode><functionid>".$funNo."</functionid><akb020>".$hospitalCode."</akb020></Request></input>";
        dump($xml);//die();

        $client=new \SoapClient(C('URL_API'));
        //$client='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);//die();
        $response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();
        
        $te_arry=$result_list['item']['deptCode'];
        $ywsz_jj=$result_list['item'];
        if(is_array($result_list['resultMessage']))
        {
            $llmessage='';  
        }else{
            $llmessage=$result_list['resultMessage']; 
        }; 
        if($result_list['resultCode']=='0')
        {
            $returnArr['status'] = 1;
            $returnArr['errorMsg']=$llmessage;   
            if($te_arry)
            {
                $returnArr['data'][0]['deptCode']=$ywsz_jj['deptCode'];     //科室代码
                $returnArr['data'][0]['deptName']=$ywsz_jj['deptName'];     //科室名称
                $returnArr['data'][0]['hasChild']=$ywsz_jj['hasChild'];     //是否有子科室 0：无子科室1：有子科室
                $returnArr['data'][0]['parentDeptCode']=$ywsz_jj['parentDeptCode'];//父科室代码 0：无父科室
                $returnArr['data'][0]['deptDescription']=$ywsz_jj['deptDescription'];   //科室介绍
                $returnArr['data'][0]['deptLocation']=$ywsz_jj['deptLocation'];   //科室位置描述

                if(is_array($ywsz_jj['deptDescription']))
                {
                    $returnArr['data'][0]['deptDescription']='';  
                }else
                {
                    $returnArr['data'][0]['deptDescription']=$ywsz_jj['deptDescription']; 
                };

                if($ywsz_jj['deptLocation']=='null')
                {
                    $returnArr['data'][0]['deptLocation']='';  
                }else
                {
                    $returnArr['data'][0]['deptLocation']=$ywsz_jj['deptLocation']; 
                };
            } else { 
                foreach ($ywsz_jj as $k => $v) {
                    $returnArr['data'][$k]['deptCode']=$ywsz_jj[$k]['deptCode'];     //科室代码
                    $returnArr['data'][$k]['deptName']=$ywsz_jj[$k]['deptName'];     //科室名称
                    $returnArr['data'][$k]['hasChild']=$ywsz_jj[$k]['hasChild'];     //是否有子科室 0：无子科室1：有子科室
                    $returnArr['data'][$k]['parentDeptCode']=$ywsz_jj[$k]['parentDeptCode'];//父科室代码 0：无父科室
                    $returnArr['data'][$k]['deptDescription']=$ywsz_jj[$k]['deptDescription'];   //科室介绍
                    $returnArr['data'][$k]['deptLocation']=$ywsz_jj[$k]['deptLocation'];   //科室位置描述

                    if(is_array($ywsz_jj[$k]['deptDescription']))
                    {
                        $returnArr['data'][$k]['deptDescription']='';  
                    }else
                    {
                        $returnArr['data'][$k]['deptDescription']=$ywsz_jj[$k]['deptDescription']; 
                    };

                    if($ywsz_jj[$k]['deptLocation']=='null')
                    {
                        $returnArr['data'][$k]['deptLocation']='';  
                    }else
                    {
                        $returnArr['data'][$k]['deptLocation']=$ywsz_jj[$k]['deptLocation']; 
                    };
                }
            }
        }else
        {//格式化为标准接口模式
            $returnArr['status'] = 2;
            $returnArr['errorMsg'] = $llmessage;
        };
        dump($returnArr);
        /* 记录请求日志   */
            $fileContent = var_export($returnArr, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetDept_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        echo json_encode($returnArr);
    }

    /**
     * 号源信息查询
     * @param 
     */
    function GetSchedule(){
        $hospitalcode='525009'; //医院编码
        $deptcode='2011401';       //科室编号
        $doctorcode='02641';       //医生编号
        $startdate='2017-12-26';      //
        $enddate='2017-12-31';
        $funNo='HIS003';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><deptcode>".$deptcode."</deptcode><doctorcode>".$doctorcode."</doctorcode><startdate>".$startdate."</startdate><enddate>".$enddate."</enddate><functionid>".$funNo."</functionid><akb020>".$hospitalcode."</akb020></Request></input>";
        dump($xml);//die();

        $client=new \SoapClient(C('URL_API'));
        //$client='http://10.166.121.249:8089/xtpt/services/yinHaiBusiness?wsdl';
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);die();
    }

    /**
     * 挂号锁号
     * @param 
     */
    function GetRegisteredlock(){
        $hospitalcode='525001'; //医院编码
        $userid='tc_123';         //第三方ID
        $code ='1582517';   //医院挂号序号
        $psordnum ='TC2017122605';   //平台订单号 TC2017120501  TC20171205
        $deptcode='3028';      //科室代码
        $doctorcode='002003';    //医生代码
        $scheduledate='2017-12-26';      //号源日期
        $timeflag='1';      //时段 1：上午 2：下午3：晚上
        $begintime='08:00';     //分时开始时间
        $endtime='12:00';       //分时结束时间
        $regfee='27';        //挂号费
        $pattype='1';       //患者类型 1成年，2儿童
        $patname='张小波';       //患者姓名
        $patsex='m';        //性别 m：男，f：女
        $patage='34';        //年龄
        $patbirth='1989-12-28';      //出生年月
        $patidtype='1';     //患者证件类型 身份证 1 居住证 2 签证   3 护照   4 户口本 5 军人证 6 港澳通行证 7 其他   8
        $patidno='429006198912281230';       //患者证件号码
        $patmobile='13507514320';     //手机号码
        $pataddress='四川攀枝花';    //地址
        $guardname='';     //监护人姓名
        $guardidtype='';   //监护人证件类型
        $guardidno='';     //监护人证件号

        $funNo='HIS004';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><code>".$code."</code><psordnum>".$psordnum."</psordnum><deptcode>".$deptcode."</deptcode><doctorcode>".$doctorcode."</doctorcode><scheduledate>".$scheduledate."</scheduledate><timeflag>".$timeflag."</timeflag><begintime>".$begintime."</begintime><endtime>".$endtime."</endtime><regfee>".$regfee."</regfee><pattype>".$pattype."</pattype><patname>".$patname."</patname><patsex>".$patsex."</patsex><patage>".$patage."</patage><patbirth>".$patbirth."</patbirth><patidtype>".$patidtype."</patidtype><patidno>".$patidno."</patidno><patmobile>".$patmobile."</patmobile><pataddress>".$pataddress."</pataddress><guardname>".$guardname."</guardname><guardidtype>".$guardidtype."</guardidtype><guardidno>".$guardidno."</guardidno><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        dump($xml);
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetRegisteredlock_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);

        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetRegisteredlock_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        dump($result_list);//die();
        $response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();
    }
    
    /**
     * 号源取消锁定
     * @param 
     */
    function GetScheduleUnlock(){
        $hospitalcode='525009'; //医院编码
        $userid='';         //第三方ID
        $hisordnum='gh|-407|11';   //医院订单号
        $psordnum='TC2017120502';      //平台订单号
        $cancelreason=''; //取消原因

        $funNo='HIS005';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><hisordnum>".$hisordnum."</hisordnum><psordnum>".$psordnum."</psordnum><cancelreason>".$cancelreason."</cancelreason><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetScheduleUnlock_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);

        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);//die();
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetScheduleUnlock_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();      
    }

    /**
     * 挂号记录查询
     * @param 
     */
    function GetRegisteredRecords(){
        $hospitalcode='525001'; //医院编码525009
        $userid='tc_123';         //第三方ID tc_123
        $patname='卢云芳';   //患者姓名 张小波
        $patidno='51041119440917302X';      //患者身份证 429006198912281230

        $funNo='HIS006';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><patname>".$patname."</patname><patidno>".$patidno."</patidno><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetRegisteredRecords_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);//die();
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetRegisteredRecords_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();

        
    }

    /**
     * 费用支付通知
     * @param 
     */
    function GetFeePaynot(){
        $hospitalcode='525009'; //医院编码
        $userid='tc_123';         //第三方ID
        $hisordnum='gh|176872|6|1';   //医院订单号
        $psordnum='TC2017121103';      //平台订单号
        $medicarenum='';   //医保就诊序号 当为社保卡时此项不能为空
        $costtype='2';      //费用类型 1挂号费2门诊费
        $paymode='1';       //支付方式 1：微信支付 2：支付宝 3:社保卡
        $payamt='10.00';        //总费用
        $coordinationpay='';      //医保统筹支付
        $scardamt='';      //医保个人账户支付
        $cashpay='10.00';       //现金支付金额
        $cardaccount='';  //账户余额  医保支付时返回支付后余额
        $isaddpay='2';      //是否有门诊调增费用 1是,2否
        $agtordnum='wx2017121103';   //收单机构流水号 对应收单机构（如微信、支付宝）用于标识一笔支付交易的流水号
        $paytime='2017-12-11 15:44:23';  //支付时间 格式：yyyy-mm-dd 24hh:mi:ss 

        /*$hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $userid  = $_POST['userid'];        //第三方ID
        $hisordnum  = $_POST['hisordnum'];  //医院订单号
        $psordnum  = $_POST['psordnum'];    //平台订单号
        $medicarenum  = $_POST['medicarenum'];      //医保就诊序号 当为社保卡时此项不能为空
        $costtype  = $_POST['costtype'];    //费用类型 1挂号费2门诊费
        $paymode  = $_POST['paymode'];      //支付方式 1：微信支付 2：支付宝 3:社保卡
        $payamt  = $_POST['payamt'];        //总费用
        $coordinationpay  = $_POST['coordinationpay'];  //医保统筹支付
        $scardamt  = $_POST['scardamt'];    //医保个人账户支付
        $cashpay  = $_POST['cashpay'];      //现金支付金额
        $cardaccount   = $_POST['cardaccount']; //账户余额  医保支付时返回支付后余额
        $isaddpay  = $_POST['isaddpay'];    //是否有门诊调增费用 1是,2否
        $agtordnum  = $_POST['agtordnum'];  //收单机构流水号
        $paytime  = $_POST['paytime'];      //支付时间*/

        $funNo='HIS008';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><hisordnum>".$hisordnum."</hisordnum><psordnum>".$psordnum."</psordnum><akc190>".$medicarenum."</akc190><costtype>".$costtype."</costtype><paymode>".$paymode."</paymode><payamt>".$payamt."</payamt><coordinationpay>".$coordinationpay."</coordinationpay><scardamt>".$scardamt."</scardamt><cashpay>".$cashpay."</cashpay><cardaccount>".$cardaccount ."</cardaccount><isaddpay>".$isaddpay."</isaddpay><agtordnum>".$agtordnum."</agtordnum><paytime>".$paytime."</paytime><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";

        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetFeePaynot_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);//die();
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetFeePaynot_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();

    }

    /**
     * 门诊缴费记录查询(包含 待缴费,已缴费，作废)
     * @param 
     */
    function GetPaymentRecords(){
        $hospitalcode='525001'; //医院编码525009
        $userid='oRln-vqRZz3SBx8wbcEKUqZDtork';             //第三方ID tc_123
        $patidno='51041119440917302X';     //身份证号 429006198912281230
        $patname='卢云芳';       //姓名 张小波
        $payflag='2';       //单据状态 1表示待缴费 2表示已缴费3作废  

        /*$hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $userid  = $_POST['userid'];        //第三方ID
        $patidno  = $_POST['patidno'];      //身份证号
        $patname  = $_POST['patname'];      //姓名
        $payflag  = $_POST['payflag'];*/      //单据状态 1表示待缴费 2表示已缴费3作废 

        $funNo='HIS009';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><patidno>".$patidno."</patidno><patname>".$patname."</patname><payflag>".$payflag."</payflag><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetPaymentRecords_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);//die();
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetPaymentRecords_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();
    }

    /**
     * 门诊缴费记录明细查询
     * @param 
     */
    function GetPaymentRecordsDetails(){
        $hospitalcode='525009'; //医院编码 525009
        $userid='tc_123';             //第三方IDtc_123
        $hisordnum='000051283800|9';     //医院订单号  000051283800|9

        /*$hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $userid  = $_POST['userid'];        //第三方ID
        $hisordnum  = $_POST['hisordnum'];      //医院订单号*/

        $funNo='HIS010';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><hisordnum>".$hisordnum."</hisordnum><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        dump($xml);
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetPaymentRecordsDetails_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);

        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);//die();
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetPaymentRecordsDetails_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();
    }

    /**
     * 订单取消或者是退费
     * @param 
     */
    function GetOrderRefund(){
        $hospitalcode='525009'; //医院编码
        $userid='tc_123';             //第三方ID
        $hisordnum='gh|-407|14|1';   //医院订单号
        $psordnum='TC2017120602';    //平台订单号
        $medicarenum='';     //医保就诊序号
        $paymode='1';     //支付方式 1：微信支付   2：支付宝   3:社保卡
        $payamt='19.00';      //总费用
        $agtordnum='wx2017120602';   //收单机构流水号  

        /*$hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $userid  = $_POST['userid'];        //第三方ID
        $hisordnum  = $_POST['hisordnum'];      //医院订单号
        $psordnum  = $_POST['psordnum'];      //平台订单号
        $medicarenum  = $_POST['medicarenum'];      //医保就诊序号
        $paymode  = $_POST['paymode'];      //支付方式 1：微信支付   2：支付宝   3:社保卡
        $payamt  = $_POST['payamt'];      //总费用
        $agtordnum  = $_POST['agtordnum'];      //收单机构流水号*/

        $funNo='HIS011';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><hisordnum>".$hisordnum."</hisordnum><psordnum>".$psordnum."</psordnum><akc190>".$medicarenum."</akc190><paymode>".$paymode."</paymode><payamt>".$payamt."</payamt><agtordnum>".$agtordnum."</agtordnum><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetOrderRefund_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);//die();
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetOrderRefund_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $response = simplexml_load_string($xml_re ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();

        
    }

    /**
     * 检验报告列表查询
     * @param 
     */
    function GetInspectionReport(){
        $hospitalcode='525001'; //医院编码 525009
        $userid='tc_123';             //第三方ID
        $patidno='510411196712071412';     //身份证号 320106198310290811
        $patname='蔡福革';       //姓名 周杰
        $begindate='2017-12-21';   //开始日期2017-04-01
        $enddate='2017-12-21';     //结束日期2017-12-11

        $funNo='HIS012';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><patidno>".$patidno."</patidno><patname>".$patname."</patname><begindate>".$begindate."</begindate><enddate>".$enddate."</enddate><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetInspectionReport_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);//die();
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetInspectionReport_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();       
    }

    /**
     * 检验报告详情查询
     * @param 
     */
    function GetInspectionDetails(){
        $hospitalcode='525001'; //医院编码
        $userid='tc_123';             //第三方ID
        $patidno='510411196712071412';     //身份证号429006198912281230
        $patname='蔡福革';     //姓名张小波
        $inspectid='1006529506';   //检验id 1712101055 

        /*$hospitalcode  = $_POST['hospitalcode'];    //医院编码
        $userid  = $_POST['userid'];        //第三方ID
        $patidno  = $_POST['patidno'];      //身份证号
        $patname  = $_POST['patname'];      //姓名
        $inspectid  = $_POST['inspectid'];  //检验id*/

        $funNo='HIS013';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><Request><functionid>".$funNo."</functionid><patidno>".$patidno."</patidno><patname>".$patname."</patname><inspectid>".$inspectid."</inspectid><akb020>".$hospitalcode."</akb020><yad901>".$userid."</yad901></Request></input>";
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetInspectionDetails_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        dump($result_list);//die();   
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetInspectionDetails_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();      
    }

    /**
     * 医保预结算
     * @param 
     */
    function GetPreSettlement(){
        $tcylkey = C('TCYL_KEY');
        $hospital_org_id='525009'; //医院编码
        $channel_id='1';      //渠道号 1 微信 2 支付宝 3.银联
        $pay_type='1';        //结算类型 1为挂号2为门诊
        $user_id=$tcylkey.'ohNH9spztdajN8bGok-hJjcfrZAk';      //第三方ID
        $social_card_no='D1516917X';  //社保卡号
        $user_card_no='510402198308010012'; //身份证
        $user_name='李建辉';    //姓名
        $ssp_order_id='TC2017120901';   //平台id
        $order_no='外部平台流水号';    //医院订单号
        $total_amount='18.00';  //医保总金额
        $funNo='HIS016';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><inputxml><inputxml><hospital_org_id>".$hospital_org_id."</hospital_org_id><channel_id>".$channel_id."</channel_id><pay_type>".$pay_type."</pay_type><user><user_id>".$user_id."</user_id><social_card_no>".$social_card_no."</social_card_no><user_card_no>".$user_card_no."</user_card_no><user_name>".$user_name."</user_name></user><order><ssp_order_id>".$ssp_order_id."</ssp_order_id><order_no>".$order_no."</order_no><total_amount>".$total_amount."</total_amount><insurance_amount>".$insurance_amount."</insurance_amount><selfpay_amount>".$selfpay_amount."</selfpay_amount></order></inputxml></inputxml></input>";
        dump($xml);
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetPreSettlement_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetPreSettlement_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        dump($result_list);//die();
        $response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();  
    }

    /**
     * 医保结算
     * @param 
     */
    function GetSettlement(){
        $tcylkey = C('TCYL_KEY');
        $hospital_org_id='525009'; //医院编码
        $channel_id='1';      //渠道号 1 微信 2 支付宝 3.银联
        $user_id=$tcylkey.'ohNH9spztdajN8bGok-hJjcfrZAk';      //第三方ID
        $social_card_no='D1516917X';  //社保卡号
        $user_card_no='510402198308010012'; //身份证
        $user_name='李建辉';                //姓名
        $ssp_order_id='TC2017120901';       //平台id
        $pay_time='2017-12-09 11:16:12';    //结算时间
        $order_no='外部平台流水号';    //医院订单号
        $total_amount='18.00';      //总交易金额
        $insurance_amount='18';
        $selfpay_amount='0';
        $funNo='HIS017';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><inputxml><inputxml><hospital_org_id>".$hospital_org_id."</hospital_org_id><channel_id>".$channel_id."</channel_id><user><user_id>".$user_id."</user_id><social_card_no>".$social_card_no."</social_card_no><user_card_no>".$user_card_no."</user_card_no><user_name>".$user_name."</user_name></user><order><ssp_order_id>".$ssp_order_id."</ssp_order_id><pay_time>".$pay_time."</pay_time><order_no>".$order_no."</order_no><total_amount>".$total_amount."</total_amount><insurance_amount>".$insurance_amount."</insurance_amount><selfpay_amount>".$selfpay_amount."</selfpay_amount></order></inputxml></inputxml></input>";
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetSettlement_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetSettlement_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        dump($result_list);//die();
        $response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();
    }

    /**
     * 单笔结算查询
     * @param 
     */
    function GetSettlementInquiry(){
        $tcylkey = C('TCYL_KEY');
        //$hospital_org_id='525009'; //医院编码
        //$channel_id='1';      //渠道号 1 微信 2 支付宝 3.银联
        $user_id=$tcylkey.'ohNH9spztdajN8bGok-hJjcfrZAk';      //第三方ID
        $ssp_order_id='TC2017120901';       //平台id
        $funNo='HIS018';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><user_id>".$user_id."</user_id><ssp_order_id>".$ssp_order_id."</ssp_order_id></input>";
        dump($xml);
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetSettlementInquiry_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetSettlementInquiry_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        dump($result_list);//die();
        $response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();
    }

    /**
     * 取消结算
     * @param 
     */
    function GetCancelSettlement(){
        $tcylkey = C('TCYL_KEY');
        //$hospital_org_id='525009'; //医院编码
        $channel_id='1';      //渠道号 1 微信 2 支付宝 3.银联
        $user_id=$tcylkey.'ohNH9spztdajN8bGok-hJjcfrZAk';      //第三方ID
        $social_card_no='D1516917X';  //社保卡号
        $user_card_no='510402198308010012'; //身份证
        $user_name='李建辉';                //姓名
        $ssp_order_id='TC2017120901';       //平台id
        $order_no='外部平台流水号';    //医院订单号
        $treatment_record_id='100000031052519';     //医保就诊序号    医保唯一对账使用
        $total_amount='18.00';      //总交易金额
        $insurance_amount='18';
        $selfpay_amount='0';
        $cancel_datetime='2017-12-09 11:54:22';
        $funNo='HIS019';    //交易编号
        //dump(C('URL_API'));die();
        $xml="<input><inputxml><inputxml><channel_id>".$channel_id."</channel_id><user><user_id>".$user_id."</user_id><social_card_no>".$social_card_no."</social_card_no><user_card_no>".$user_card_no."</user_card_no><user_name>".$user_name."</user_name></user><order><ssp_order_id>".$ssp_order_id."</ssp_order_id><order_no>".$order_no."</order_no><treatment_record_id>".$treatment_record_id."</treatment_record_id><total_amount>".$total_amount."</total_amount><insurance_amount>".$insurance_amount."</insurance_amount><selfpay_amount>".$selfpay_amount."</selfpay_amount><cancel_datetime>".$cancel_datetime."</cancel_datetime></order></inputxml></inputxml></input>";
        /* 记录请求日志   */
            $fileContent = var_export($xml, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetSettlement_rc/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        $client=new \SoapClient(C('URL_API'));
        $result_list=$this->Get_service_api($xml,$funNo,$client);
        /* 记录请求日志   */
            $fileContent = var_export($result_list, true);
            $dir = "soapGetDate/" . date("Y-m-d") . "/WXsb_GetSettlement_Re/";
            $filename = date("H_i_s") . "_" . rand(10000, 99999);
            writeLog($dir, $filename, $fileContent);
        dump($result_list);//die();
        $response = simplexml_load_string($result_list ,'SimpleXMLElement', LIBXML_NOCDATA);
        $response = json_encode($response);
        echo $response;die();
    }
    /********************php验证身份证号码是否正确函数*********************/
    function is_idcard($id) 
    { 
        $id = strtoupper($id); 
        $regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/"; 
        $arr_split = array(); 
        if(!preg_match($regx, $id)) 
        { 
            return FALSE; 
        } 
        if(15==strlen($id)) //检查15位 
        { 
            $regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";      
            @preg_match($regx, $id, $arr_split); 
            //检查生日日期是否正确 
            $dtm_birth = "19".$arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4]; 
            if(!strtotime($dtm_birth)) 
            { 
                return FALSE; 
            } else { 
                return TRUE; 
            } 
        } 
        else      //检查18位 
        { 
            $regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/"; 
            @preg_match($regx, $id, $arr_split); 
            $dtm_birth = $arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4]; 
            if(!strtotime($dtm_birth)) //检查生日日期是否正确 
            { 
                return FALSE; 
            } 
            else
            { 
                //检验18位身份证的校验码是否正确。 
                //校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。 
                $arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); 
                $arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); 
                $sign = 0; 
                for($i = 0; $i < 17; $i++ ) 
                { 
                    $b = (int) $id{$i}; 
                    $w = $arr_int[$i]; 
                    $sign += $b * $w; 
                } 
                $n = $sign % 11; 
                $val_num = $arr_ch[$n]; 
                if($val_num != substr($id,17, 1)) 
                { 
                    return FALSE; 
                } //phpfensi.com 
                else
                { 
                    return TRUE; 
                } 
            } 
        } 
      
    } 

}
?>